home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / imap / ANSI / c-client / log_vms.c < prev    next >
C/C++ Source or Header  |  1994-08-02  |  4KB  |  104 lines

  1.  /*
  2.  * Program:    Standard server login - VMS version
  3.  *
  4.  * Author:    Yehavi Bourvine, The Hebrew University of Jerusalem
  5.  *        Internet: Yehavi@VMS.HUJI.AC.IL
  6.  *
  7.  * Date:    2 August 1994
  8.  * Last Edited:    2 August 1994
  9.  *
  10.  * Copyright 1994 by the University of Washington
  11.  *
  12.  *  Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose and without fee is hereby granted, provided
  14.  * that the above copyright notice appears in all copies and that both the
  15.  * above copyright notice and this permission notice appear in supporting
  16.  * documentation, and that the name of the University of Washington not be
  17.  * used in advertising or publicity pertaining to distribution of the software
  18.  * without specific, written prior permission.    This software is made available
  19.  * "as is", and
  20.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  21.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  22.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  23.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  24.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  25.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  26.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  27.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  28.  *
  29.  */
  30.  
  31. #include <uaidef.h>
  32. #include <rmsdef.h>
  33.  
  34.  
  35. /* Standard string descriptor */
  36.  
  37. struct DESC {
  38.   short length, type;        /* length of string and descriptor type */
  39.   char    *address;        /* buffer's address */
  40. };
  41.  
  42.  
  43. /* Item list for passing parameters to the mail routines */
  44.  
  45. struct ITEM_LIST {
  46.   short length;            /* buffer length */
  47.   short code;            /* item/action code */
  48.   char *buffer;            /* input buffer address */
  49.   int *olength;            /* where to place result length if requested */
  50. };
  51.  
  52. /* These should come from some #include file */
  53.  
  54. int sys$getuai ();
  55. int sys$hash_password ();
  56.  
  57. /* Server log in
  58.  * Accepts: user name string
  59.  *        password string
  60.  *        optional place to return home directory
  61.  * Returns: T if password validated, NIL otherwise
  62.  */
  63.  
  64. long server_login (char *username,char *password,char **home,int argc,
  65.            char *argv[])
  66. {
  67.   int status,uai_flags;
  68.   unsigned long uai_pwd[2],putative_pw[2];
  69.   unsigned short uai_salt;
  70.   unsigned char uai_encrypt;
  71.   struct DESC usernameD, passwordD;
  72.   char *p,Username[MAILTMPLEN],Password[MAILTMPLEN];
  73.   struct ITEM_LIST itmlst[] = {
  74.     {sizeof (uai_flags),    UAI$_FLAGS,    &uai_flags,    NULL},
  75.     {sizeof (uai_encrypt),    UAI$_ENCRYPT,    &uai_encrypt,    NULL},
  76.     {sizeof (uai_salt),        UAI$_SALT,    &uai_salt,    NULL},
  77.     {8,                UAI$_PWD,    uai_pwd,    NULL},
  78.     {0,                0,        NULL,        NULL}
  79.   };
  80.                 /* empty user name or password */
  81.   if (!*username || !*password) return NIL;
  82.                 /* make uppercase copy of user name */
  83.   usernameD.address = ucase (strcpy (Username,username));
  84.   usernameD.length = strlen (Username);
  85.   usernameD.type = 0;
  86.                 /* get record for user name */
  87.   if (!((status = sys$getuai (0,0,&usernameD,itmlst,0,0,0)) & 0x1)) return NIL;
  88.                 /* if not found, or disuser'd */
  89.   if (status == RMS$_RNF || (UAI$M_DISACNT & uai_flags)) return NIL;
  90.                 /* make uppercase copy of password */
  91.   passwordD.address = ucase (strcpy (Password,password));
  92.   passwordD.length = strlen (password);
  93.   passwordD.type = 0;
  94.                 /* hash the password */
  95.   if (!(sys$hash_password (&passwordD,uai_encrypt,uai_salt,&usernameD,
  96.                putative_pw) & 0x1)) return NIL;
  97.                 /* password must match */
  98.   if ((putative_pw[0] != uai_pwd[0]) || putative_pw[1] != uai_pwd[1])
  99.     return NIL;
  100.                 /* get mail directory */
  101.   vms_mail_get_user_directory (Username, home);
  102.   return T;
  103. }
  104.